import { ref } from 'vue'
import { defineStore } from 'pinia'
import menuApi from '@/api/menu'

export const useHeaderStore = defineStore('header', () => {
    const breadcrumbs  = ref([]) 
    var menus = menuApi.getMenus()
    const setBreadcrumbs = (id)=>{
        breadcrumbs.value = []
        var ids = id.split('-')
        var temp = menus.find(x=>x.id == ids[0])
        breadcrumbs.value.push({title:temp.title,name:temp.name})
        if(temp.children){
            temp = temp.children.find(x=>x.id == id)
            breadcrumbs.value.push({title:temp.title,name:temp.name})
        }
    }


    return {breadcrumbs,setBreadcrumbs}



},
    {
        persist: true,
    },)
